import request from "@/utils/service"
import type * as ISystem from "./types/index"

/** 获取角色列表 */
export function getRoleListApi(params?: ISystem.IListParams) {
  return request<ISystem.SystemListResponseData<ISystem.IRoleListData[]>>({
    url: "/api/v2/role/getRoleList",
    method: "get",
    params
  })
}

/** 根据身份获取权限 */
export function getRoleNodeApi(params: { role_id: number }) {
  return request<ISystem.SystemResponseData<number[]>>({
    url: "/api/v2/node/getRoleNode",
    method: "get",
    params
  })
}

/** 获取所有权限 */
export function getRoleAllNodeApi() {
  return request<ISystem.SystemResponseData<ISystem.IRoleTreeData[]>>({
    url: "/api/v2/node/getAllNode",
    method: "get"
  })
}

/** 新增角色 */
export function addRoleApi(data: ISystem.IAddOrEditRoleParams) {
  return request<ISystem.SystemResponseData<any>>({
    url: "/api/v2/role/addRole",
    method: "post",
    data
  })
}

/** 编辑角色 */
export function editRoleApi(data: ISystem.IAddOrEditRoleParams) {
  return request<ISystem.SystemResponseData<any>>({
    url: "/api/v2/role/setRole",
    method: "put",
    data
  })
}

/** 删除角色 */
export function delRoleApi(data: { role_id: number }) {
  return request<ISystem.SystemResponseData<any>>({
    url: "/api/v2/role/delRole",
    method: "delete",
    data
  })
}

/**
 * 用户相关接口
 */

/** 获取用户列表数据 */
export function getUserListApi(params: Partial<ISystem.IUserListParams>) {
  return request<ISystem.SystemListResponseData<ISystem.IUserListData[]>>({
    url: "/api/v2/user/getUserList",
    method: "get",
    params
  })
}

/** 删除用户 */
export function delUserApi(data: ISystem.IUserDelParams) {
  return request<ISystem.SystemResponseData<any>>({
    url: "/api/v2/user/delUser",
    method: "delete",
    data
  })
}

/** 停用禁用用户 */
export function enableUserApi(data: ISystem.IUserEnableParams) {
  return request<ISystem.SystemResponseData<any>>({
    url: "/api/v2/user/enableUser",
    method: "put",
    data
  })
}

/** 新增用户 */
export function addUserApi(data: ISystem.IAddUserParams) {
  return request<ISystem.SystemResponseData<any>>({
    url: "/api/v2/user/adduser",
    method: "post",
    data
  })
}

/** 修改用户 */
export function editUserApi(data: ISystem.IEditUserParams) {
  return request<ISystem.SystemResponseData<any>>({
    url: "/api/v2/user/saveUser",
    method: "put",
    data
  })
}
